package com.study.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.study.beans.User;

@RestController
public class ConsumerController {
	
//	private static final String REST_URL = "http://localhost:8001/user";
	private static final String REST_URL = "http://CLOUD-PROVIDER/user";

	@Autowired
	private RestTemplate restTemplate;
	
	@GetMapping("/consumer/add")
	public ResponseEntity<Boolean> add(User user) {
		return restTemplate.postForEntity(REST_URL+"/add", user, Boolean.class);
	}
	
	@GetMapping("/consumer/get/{id}")
	public ResponseEntity<User> get(@PathVariable("id") Integer id) {
		return restTemplate.getForEntity(REST_URL+"/get/"+id, User.class);
	}
	
	@SuppressWarnings("rawtypes")
	@GetMapping("/consumer/list")
	public ResponseEntity<List> list() {
		return restTemplate.getForEntity(REST_URL+"/list", List.class);
	}
	
	@GetMapping("/consumer/discovery")
	public ResponseEntity<Object> discovery() {
		return restTemplate.getForEntity(REST_URL+"/discovery", Object.class);
	}
}
